package com.yuanchu.store.controller;

import com.yuanchu.common.utils.PageResult;
import com.yuanchu.common.utils.R;
import com.yuanchu.store.dto.StoreSettingParamsDto;
import com.yuanchu.store.entity.YoshopExpressEntity;
import com.yuanchu.store.service.YoshopStoreSettingService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @version: 1.0
 * @Author: adan
 * @description:
 * @date: 2024-02-27 13:24
 */
@RestController
@RequestMapping("setting")
public class StoreSettingController {
    @Resource
    private YoshopStoreSettingService storeSettingService;
    int storeId = 10001;

    // @GetMapping("/detail")
    // public R queryStoreSettingDetail(@RequestParam("key") String key)
    // {
    //     EditStoreSettingDto.StoreSettingForm map = storeSettingService.queryStoreSettingDetail(key, storeId);
    //     Map<String, Object> values = new HashMap<>();
    //     values.put("values", map);
    //     return R.ok().put("data", values);
    // }
    @GetMapping("/detail")
    public R queryStoreSettingDetail(@RequestParam("key") String key)
    {
        StoreSettingParamsDto.SettingForm map = storeSettingService.queryStoreSettingDetail(key);
        Map<String, Object> values = new HashMap<>();
        values.put("values", map);
        return R.ok().put("data", values);
    }

    // @PostMapping("/update")
    // public R editStoreSetting(@RequestBody @Validated({ValidationGroups.Update.class}) EditStoreSettingDto params)
    // {
    //     boolean result = storeSettingService.updateStoreSetting(params, storeId);
    //     return R.ok().put("result", result);
    // }

    // setting
    @ApiOperation("查询商家设置信息")
    @PostMapping("/update")
    public R storeSettingInfo(@RequestBody StoreSettingParamsDto param) {
        storeSettingService.storeSettingInfo(param);
        return R.ok();
    }

    @ApiOperation("查新物流接口")
    @GetMapping("/express/all")
    public R queryExpressAll() {
        List<YoshopExpressEntity> entities = storeSettingService.queryExpressAll(storeId);
        Map<String, Object> data = new HashMap<>();
        data.put("list", entities);
        return R.ok().put("data",data );
    }

    @ApiOperation("查新物流接口")
    @GetMapping("/express/list")
    public R queryExpressList(@RequestParam("page") Integer page, @RequestParam(value = "search", required = false) String search) {
        PageResult<YoshopExpressEntity> entities = storeSettingService.queryExpressList(page, search);
        Map<String, Object> data = new HashMap<>();
        data.put("list", entities);
        return R.ok().put("data",data );
    }

    // add
    // @ApiOperation("添加物流模板")
    // @PostMapping("/express/add")
    // public R addExpress(@RequestBody ExpressParamsDto params) {
    //     storeSettingService.addExpress(params);
    //     return R.ok();
    // }
}
